package controller;
import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.test.util.JsonResult;

import entity.SysRole;
import service.SysRoleService;
/**
 * Created by wenchao.ren on 2014/4/26.
 */
@SpringBootApplication
//启注解事务管理  
@Controller
@Import (SysRoleService.class)
public class SysRoleController {

	@Autowired
	private SysRoleService sysRoleService;

	@RequestMapping(value = "sysRoleList", method = RequestMethod.GET)
    public String SysRoleList(Model model) {
    	//ModelAndView view = new ModelAndView("/sys/SysRoleList");
    	List<SysRole> sysRoleList = sysRoleService.find();
    	//view.addObject("SysRoleList", SysRoleList);
    	model.addAttribute("sysRoleList", sysRoleList);
        return "sys/sysRoleList";
    }
	
	
	@ResponseBody
	@RequestMapping(value = "sysRole_list.json")
	public List<SysRole> listSysRole() {
		List<SysRole> userList = sysRoleService.find();
		return userList;
	}
	
	@RequestMapping(value = "sysRoleEdit", method = RequestMethod.GET)
    public String userEdit(Long  seqid,Model model) {
    	SysRole sysRole = new SysRole();
    	if(seqid!=null){
    		sysRole = sysRoleService.findById(seqid);
    	}
    	model.addAttribute("sysRole", sysRole);
    	 return "sys/sysRoleEdit";
    }
	
	/**
	 * 保存用户修改信息
	 * 
	 * @param tblStage
	 * @return
	 */
	@RequestMapping(value = "sysRole_save.json")
	@ResponseBody
	public JsonResult saveUser(SysRole sysRole) {
		JsonResult result = JsonResult.newInstance();
		sysRoleService.save(sysRole);
		return result;
	}

	/**
	 * 批量删除用户
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "sysRole_del.json")
	@ResponseBody
	public JsonResult delUsers(String ids) {
		JsonResult result = JsonResult.newInstance();
		sysRoleService.deleteByIds(ids.split(","));
		return result;
	}
	
	
    
}
